<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>缺省映射 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/default-mapping.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/default-mapping.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/default-mapping.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/default-mapping.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="getting-started.html">基础入门</a></span>
»
<span class="breadcrumb-link"><a href="index-management.html">索引管理</a></span>
»
<span class="breadcrumb-node">缺省映射</span>
</div>
<div class="navheader">
<span class="prev">
<a href="custom-dynamic-mapping.html">« 自定义动态映射</a>
</span>
<span class="next">
<a href="reindex.html">重新索引你的数据 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="default-mapping"></a>缺省映射<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/070_Index_Mgmt/45_Default_Mapping.asciidoc">edit</a>
</h2>
</div></div></div>
<p>通常，一个索引中的所有类型共享相同的字段和设置。  <code class="literal">_default_</code> 映射更加方便地指定通用设置，而不是每次创建新类型时都要重复设置。 <code class="literal">_default_</code> 映射是新类型的模板。在设置 <code class="literal">_default_</code> 映射之后创建的所有类型都将应用这些缺省的设置，除非类型在自己的映射中明确覆盖这些设置。</p>
<p>例如，我们可以使用 <code class="literal">_default_</code> 映射为所有的类型禁用 <code class="literal">_all</code> 字段，  而只在 <code class="literal">blog</code> 类型启用：</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">PUT /my_index
{
    "mappings": {
        "_default_": {
            "_all": { "enabled":  false }
        },
        "blog": {
            "_all": { "enabled":  true  }
        }
    }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/070_Index_Mgmt/45_Default_mapping.json"></div>
<p><code class="literal">_default_</code> 映射也是一个指定索引 <a class="xref" href="custom-dynamic-mapping.html#dynamic-templates" title="动态模板">dynamic templates</a> 的好方法。</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="custom-dynamic-mapping.html">« 自定义动态映射</a>
</span>
<span class="next">
<a href="reindex.html">重新索引你的数据 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>